<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: PacManSprites</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.sprite</a> ]
    </div>

    <h1>Coverage Summary for Class: PacManSprites (nl.tudelft.jpacman.sprite)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">PacManSprites</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 10)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 25)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.sprite;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.io.IOException;
        <i>4</i>&nbsp;import java.util.HashMap;
        <i>5</i>&nbsp;import java.util.Map;
        <i>6</i>&nbsp;
        <i>7</i>&nbsp;import nl.tudelft.jpacman.PacmanConfigurationException;
        <i>8</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>9</i>&nbsp;import nl.tudelft.jpacman.npc.ghost.GhostColor;
        <i>10</i>&nbsp;
        <i>11</i>&nbsp;/**
        <i>12</i>&nbsp; * Sprite Store containing the classic Pac-Man sprites.
        <i>13</i>&nbsp; *
        <i>14</i>&nbsp; * @author Jeroen Roosen
        <i>15</i>&nbsp; */
        <b class="nc"><i>16</i>&nbsp;public class PacManSprites extends SpriteStore {</b>
        <i>17</i>&nbsp;
        <i>18</i>&nbsp; /**
        <i>19</i>&nbsp; * The sprite files are vertically stacked series for each direction, this
        <i>20</i>&nbsp; * array denotes the order.
        <i>21</i>&nbsp; */
        <b class="nc"><i>22</i>&nbsp; private static final Direction[] DIRECTIONS = {</b>
        <i>23</i>&nbsp; Direction.NORTH,
        <i>24</i>&nbsp; Direction.EAST,
        <i>25</i>&nbsp; Direction.SOUTH,
        <i>26</i>&nbsp; Direction.WEST
        <i>27</i>&nbsp; };
        <i>28</i>&nbsp;
        <i>29</i>&nbsp; /**
        <i>30</i>&nbsp; * The image size in pixels.
        <i>31</i>&nbsp; */
        <i>32</i>&nbsp; private static final int SPRITE_SIZE = 16;
        <i>33</i>&nbsp;
        <i>34</i>&nbsp; /**
        <i>35</i>&nbsp; * The amount of frames in the pacman animation.
        <i>36</i>&nbsp; */
        <i>37</i>&nbsp; private static final int PACMAN_ANIMATION_FRAMES = 4;
        <i>38</i>&nbsp;
        <i>39</i>&nbsp; /**
        <i>40</i>&nbsp; * The amount of frames in the pacman dying animation.
        <i>41</i>&nbsp; */
        <i>42</i>&nbsp; private static final int PACMAN_DEATH_FRAMES = 11;
        <i>43</i>&nbsp;
        <i>44</i>&nbsp; /**
        <i>45</i>&nbsp; * The amount of frames in the ghost animation.
        <i>46</i>&nbsp; */
        <i>47</i>&nbsp; private static final int GHOST_ANIMATION_FRAMES = 2;
        <i>48</i>&nbsp;
        <i>49</i>&nbsp; /**
        <i>50</i>&nbsp; * The delay between frames.
        <i>51</i>&nbsp; */
        <i>52</i>&nbsp; private static final int ANIMATION_DELAY = 200;
        <i>53</i>&nbsp;
        <i>54</i>&nbsp; /**
        <i>55</i>&nbsp; * @return A map of animated Pac-Man sprites for all directions.
        <i>56</i>&nbsp; */
        <i>57</i>&nbsp; public Map&lt;Direction, Sprite&gt; getPacmanSprites() {
        <b class="nc"><i>58</i>&nbsp; return directionSprite(&quot;/sprite/pacman.png&quot;,
            PACMAN_ANIMATION_FRAMES);</b>
        <i>59</i>&nbsp; }
        <i>60</i>&nbsp;
        <i>61</i>&nbsp; /**
        <i>62</i>&nbsp; * @return The animation of a dying Pac-Man.
        <i>63</i>&nbsp; */
        <i>64</i>&nbsp; public AnimatedSprite getPacManDeathAnimation() {
        <b class="nc"><i>65</i>&nbsp; String resource = &quot;/sprite/dead.png&quot;;</b>
        <i>66</i>&nbsp;
        <b class="nc"><i>67</i>&nbsp; Sprite baseImage = loadSprite(resource);</b>
        <b class="nc"><i>68</i>&nbsp; AnimatedSprite animation = createAnimatedSprite(baseImage,
            PACMAN_DEATH_FRAMES,</b>
        <i>69</i>&nbsp; ANIMATION_DELAY, false);
        <b class="nc"><i>70</i>&nbsp; animation.setAnimating(false);</b>
        <i>71</i>&nbsp;
        <b class="nc"><i>72</i>&nbsp; return animation;</b>
        <i>73</i>&nbsp; }
        <i>74</i>&nbsp;
        <i>75</i>&nbsp; /**
        <i>76</i>&nbsp; * Returns a new map with animations for all directions.
        <i>77</i>&nbsp; *
        <i>78</i>&nbsp; * @param resource
        <i>79</i>&nbsp; * The resource name of the sprite.
        <i>80</i>&nbsp; * @param frames
        <i>81</i>&nbsp; * The number of frames in this sprite.
        <i>82</i>&nbsp; * @return The animated sprite facing the given direction.
        <i>83</i>&nbsp; */
        <i>84</i>&nbsp; private Map&lt;Direction, Sprite&gt; directionSprite(String resource, int frames) {
        <b class="nc"><i>85</i>&nbsp; Map&lt;Direction, Sprite&gt; sprite = new HashMap&lt;&gt;();</b>
        <i>86</i>&nbsp;
        <b class="nc"><i>87</i>&nbsp; Sprite baseImage = loadSprite(resource);</b>
        <b class="nc"><i>88</i>&nbsp; for (int i = 0; i &lt; DIRECTIONS.length; i++) {</b>
        <b class="nc"><i>89</i>&nbsp; Sprite directionSprite = baseImage.split(0, i * SPRITE_SIZE, frames</b>
        <i>90</i>&nbsp; * SPRITE_SIZE, SPRITE_SIZE);
        <b class="nc"><i>91</i>&nbsp; AnimatedSprite animation = createAnimatedSprite(directionSprite,</b>
        <i>92</i>&nbsp; frames, ANIMATION_DELAY, true);
        <b class="nc"><i>93</i>&nbsp; animation.setAnimating(true);</b>
        <b class="nc"><i>94</i>&nbsp; sprite.put(DIRECTIONS[i], animation);</b>
        <i>95</i>&nbsp; }
        <i>96</i>&nbsp;
        <b class="nc"><i>97</i>&nbsp; return sprite;</b>
        <i>98</i>&nbsp; }
        <i>99</i>&nbsp;
        <i>100</i>&nbsp; /**
        <i>101</i>&nbsp; * Returns a map of animated ghost sprites for all directions.
        <i>102</i>&nbsp; *
        <i>103</i>&nbsp; * @param color
        <i>104</i>&nbsp; * The colour of the ghost.
        <i>105</i>&nbsp; * @return The Sprite for the ghost.
        <i>106</i>&nbsp; */
        <i>107</i>&nbsp; public Map&lt;Direction, Sprite&gt; getGhostSprite(GhostColor color) {
        <b class="nc"><i>108</i>&nbsp; assert color != null;</b>
        <i>109</i>&nbsp;
        <b class="nc"><i>110</i>&nbsp; String resource = &quot;/sprite/ghost_&quot; + color.name().toLowerCase()</b>
        <i>111</i>&nbsp; + &quot;.png&quot;;
        <b class="nc"><i>112</i>&nbsp; return directionSprite(resource, GHOST_ANIMATION_FRAMES);</b>
        <i>113</i>&nbsp; }
        <i>114</i>&nbsp;
        <i>115</i>&nbsp; /**
        <i>116</i>&nbsp; * @return The sprite for the wall.
        <i>117</i>&nbsp; */
        <i>118</i>&nbsp; public Sprite getWallSprite() {
        <b class="nc"><i>119</i>&nbsp; return loadSprite(&quot;/sprite/wall.png&quot;);</b>
        <i>120</i>&nbsp; }
        <i>121</i>&nbsp;
        <i>122</i>&nbsp; /**
        <i>123</i>&nbsp; * @return The sprite for the ground.
        <i>124</i>&nbsp; */
        <i>125</i>&nbsp; public Sprite getGroundSprite() {
        <b class="nc"><i>126</i>&nbsp; return loadSprite(&quot;/sprite/floor.png&quot;);</b>
        <i>127</i>&nbsp; }
        <i>128</i>&nbsp;
        <i>129</i>&nbsp; /**
        <i>130</i>&nbsp; * @return The sprite for the
        <i>131</i>&nbsp; */
        <i>132</i>&nbsp; public Sprite getPelletSprite() {
        <b class="nc"><i>133</i>&nbsp; return loadSprite(&quot;/sprite/pellet.png&quot;);</b>
        <i>134</i>&nbsp; }
        <i>135</i>&nbsp;
        <i>136</i>&nbsp; /**
        <i>137</i>&nbsp; * Overloads the default sprite loading, ignoring the exception. This class
        <i>138</i>&nbsp; * assumes all sprites are provided, hence the exception will be thrown as a
        <i>139</i>&nbsp; * {@link RuntimeException}.
        <i>140</i>&nbsp; *
        <i>141</i>&nbsp; * {@inheritDoc}
        <i>142</i>&nbsp; */
        <i>143</i>&nbsp; @Override
        <i>144</i>&nbsp; public Sprite loadSprite(String resource) {
        <i>145</i>&nbsp; try {
        <b class="nc"><i>146</i>&nbsp; return super.loadSprite(resource);</b>
        <b class="nc"><i>147</i>&nbsp; } catch (IOException e) {</b>
        <b class="nc"><i>148</i>&nbsp; throw new PacmanConfigurationException(&quot;Unable to load sprite: &quot; +
            resource, e);</b>
        <i>149</i>&nbsp; }
        <i>150</i>&nbsp; }
        <i>151</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
